<template>
  <view class="template-details">
    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed alpha customBack>
      <view slot="back" class='tn-custom-nav-bar__back'
        @click="goBack">
        <text class='icon tn-icon-left'></text>
        <text class='icon tn-icon-home-capsule-fill'></text>
      </view>
    </tn-nav-bar>
    
    <view>
			<view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur button-4" @click="collectiomImage">
			  <view class="tn-icon-like-lack"></view>
			</view>
      <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur button-3" @tap="showLandscape">
        <view class="tn-icon-level"></view>
      </view>
      <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur button-2" @click="tn('/pageA/author/author?author_uid=' + swiperList[0].author.uid)">
        <view class="tn-icon-my"></view>
      </view>
      <!-- <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur button-1" @click="tn('/pageB/chat/chat')">
        <view class="tn-icon-comment"></view>
      </view> -->
    </view>  
    
    
    <!-- 页面内容 -->
	<!-- <view class="slideshow">
		<template v-for="(item, index) in swiperList">
			<view class="slideshow-image"  @click="imagePreview(index)" :style="'background-image:url('+ item.url + item.path + ');'"></view>
		</template>
	</view> -->
	<!-- 手机设备的壁纸开始 -->
	<swiper class="card-swiper" :circular="true" v-if="device_type == 1"
      :autoplay="false" duration="500" interval="5000" @change="cardSwiper" style="background-color: #333333;"> 
      <swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
        <!-- <view class="swiper-item image-banner" @touchstart.prevent @click="$func.imagePreview(item.url + item.path)" 
				:style="'background-image:url('+ item.url + item.path + ');transform:rotate(45deg); background-size: cover;border-radius: 15rpx;background-repeat: no-repeat;'">
        </view> -->
				<view class="swiper-item image-banner" @touchstart.prevent @click="$func.imagePreview(item.url + item.path)"
				:style="'width:auto;height:100%;background-image:url('+ item.url + item.path + ');background-size: cover;background-position:center; border-radius: 15rpx;background-repeat: no-repeat;'">
				</view>
      </swiper-item>
  </swiper>
	<!-- 手机设备的壁纸结束 -->
	<!-- 电脑或者平板壁纸开始 -->
	<swiper class="card-swiper" :circular="true" v-if="device_type != 1"
	    :autoplay="false" duration="500" interval="5000" @change="cardSwiper" style="background-color: #333333;"> 
	    <swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
				<view class="swiper-item image-banner" @touchstart.prevent @click="$func.imagePreview(item.url + item.path)"
				:style="'background-image:url('+ item.url + item.path + ');background-size: 100% auto;background-position:center; border-radius: 15rpx;background-repeat: no-repeat;'">
				</view>
	    </swiper-item>
	</swiper>
	<!-- 电脑或者平板壁纸结束 -->
	
    <view class="indication">
        <block v-for="(item,index) in swiperList" :key="index">
          <view class="spot" :class="cardCur==index?'active':''"></view>
        </block>
    </view>
    <!-- .spot{
      background-color: #FFFFFF;
      opacity: 0.6;
      width: 10rpx;
      height: 10rpx;
      border-radius: 20rpx;
      top: calc(-280rpx - env(safe-area-inset-bottom) / 2);
      top: calc(-280rpx - constant(safe-area-inset-bottom));
      margin: 0 8rpx !important;
      position: relative;
    }
    
    .spot.active{
      opacity: 1;
      width: 30rpx;
      background-color: #FFFFFF;
    } -->
    
    <!-- 底部tabbar start-->
    <view class="tabbar footerfixed dd-glass tn-color-white" style="border-radius: 100rpx;">
      <!-- <view class="action" @click="collectiomImage">
        <view class="bar-icon">
          <view class="tn-icon-like-lack">
          </view> -->
          <!-- <image class="" src='https://tnuiimage.tnkjapp.com/tabbar/a1.png'></image> -->
        <!-- </view>
        <view class="">收藏</view>
      </view> -->
      <view class="action" @click="showAd">
        <view class="bar-icon">
          <view class="tn-icon-download">
          </view>
          <!-- <image class="" src='https://tnuiimage.tnkjapp.com/tabbar/k2.png'></image> -->
        </view>
        <view class="">高清下载</view>
      </view>
      <view class="action" @click="subscribe()">
        
        <view class="bar-icon">
          <view class="tn-icon-notice">
          </view>
          <!-- <image class="" src='https://tnuiimage.tnkjapp.com/tabbar/i2.png'></image> -->
        </view>
        <view class="">更新订阅</view>
      </view>
			<view class="action" @click="imagePreview()">
			  
			  <view class="bar-icon">
			    <view class="tn-icon-eye">
			    </view>
			    <!-- <image class="" src='https://tnuiimage.tnkjapp.com/tabbar/i2.png'></image> -->
			  </view>
			  <view class="">仿真预览</view>
			</view>
      <view class="action">
        <button class="tn-flex-direction-column tn-flex-row-center tn-flex-col-center tn-button--clear-style" open-type="share">
          <view class="bar-icon">
            <view class="tn-icon-send">
            </view>
            <!-- <image class="" src='https://tnuiimage.tnkjapp.com/tabbar/d2.png'></image> -->
          </view>
          <view class="">分享好友</view>  
        </button>
      </view>
    </view>
    
    <!-- 压屏窗-->
    <tn-landscape :show="show1" @close="closeLandscape" closePosition="bottom" :closeSize="60">
      <view class="tn-color-white" style="width: 100vw;">
        
        <view class="" style="margin: 120rpx 60rpx;">
          <view class="tn-flex tn-flex-col-top">
        
            <view class="">
              <view class="logo-pic tn-shadow">
                <view class="logo-image">
					<view class="tn-shadow-blur" :style="'background-image:url('+ swiperList[0].author.qr_url +');width: 100rpx;height: 100rpx;background-size: cover;'">
                  </view>
                </view>
              </view>
              <view class="tn-icon-sex-male" style="position: absolute;margin: -105rpx 0 0 72rpx;border-radius: 100rpx;background-color: #FFFFFF;color: #FF71D2;padding: 5rpx;"></view>
            </view>
            <view class="tn-padding-left-sm tn-padding-top-xs" style="width: 100%;">
              <view class="tn-flex tn-flex-row-between tn-flex-col-between">
                <view class="justify-content-item">
                  <text class="tn-text-lg tn-text-bold">{{swiperList[0].author.nickname}}</text>
                  <text class="tn-padding-left-sm tn-padding-right-xs">水瓶座</text>
                  <text class="tn-icon-con-virgo"></text>
                </view>
                <!-- <view class="justify-content-item tn-round tn-text-xs tn-bg-orangered--light tn-color-orangered" style="padding: 5rpx 15rpx;">
                  <text class="tn-icon-warning-fill tn-padding-right-xs"></text> 举报
                </view> -->
              </view>
              <view class="tn-padding-top-xs">
                <view class="">
                  <text class="tn-text-df tn-color-gray--light">{{swiperList[0].upload_time}}</text>
                </view>
              </view>
            </view>
          </view>
        
          
          <view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-xl tn-text-justify">
            <text class="">{{ swiperList[0].author.remark }}</text>
          </view>
        </view>
  
        
      </view>
    </tn-landscape>
		
		<view class="" v-if="device_type == 1" style="position: fixed;margin:10px 0 0 20px;z-index: 100000;top: 260rpx;transform: translate(-50%, -50%);left:45%;">
			<view class="" style="display: flex;flex-direction: column;justify-content: center;text-align: center;">
				<view class="" style="font-size: 100rpx;letter-spacing: 6rpx;">
					{{currentTime}}
				</view>
				<view class="" style="font-size: 50rpx;margin-top: 20rpx;letter-spacing: 8rpx;">
					{{day}}
				</view>
			</view>
		</view>
    
  </view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import { imageItemList, imageDownLoad, imageShow, imageCollection, imageShare } from '@/utils/api/image'
	// import mpShare  from '@/tuniao-ui/libs/mixin/mpShare.js'
	
  export default {
    name: 'TemplateDetails',
    mixins: [template_page_mixin],
    data(){
      return {
        show1: false,
        cardCur: 0,
        swiperList: [],
				image_uid: '',
				device_type: 1,
				currentTime: '00:00',
				day: '',
				imageContent: {},
      }
    },
		onLoad(options) {
			this.image_uid = options.image_uid || ""
			this.device_type = options.device_type || 1,
			this.getImageShow()
			this.getImageItemList()
		},
		onShow() {
			// 默认就执行一个关闭事件，因为用户在点击下载时，可能为登录，就会默认跳转到登录页面，登录页面回退回来，无法关闭loading
			uni.hideLoading()
			this.getCurrentTime()
		},
    methods: {
			// 壁纸收藏
			collectiomImage() {
				imageCollection({image_uid: this.image_uid}).then(res => {
					this.$func.showToast(res.msg)
				})
			},
			getImageShow() {
				let _that = this
				imageShow({uid:this.image_uid}).then(res => {
					_that.imageContent = res
					_that.$t.mpShare.title = res.title
				})
			},
			getCurrentTime() {
				var currentTime = new Date()
				var hours = currentTime.getHours().toString().padStart(2, '0')
				var minutes = currentTime.getMinutes().toString().padStart(2, '0')
				var seconds = currentTime.getSeconds().toString().padStart(2, '0')
				var timeString = hours + ':' + minutes// + ':' + seconds
				this.currentTime = timeString
				var days = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
				this.day = days[currentTime.getDay()]
			},
			getImageItemList() {
				imageItemList({image_uid: this.image_uid}).then(res => {
					this.swiperList = res.items
					this.$t.mpShare.imageUrl = res.items[0].url + res.items[0].path
				})
			},
      // 跳转
      tn(e) {
        uni.navigateTo({
          url: e,
        })
      },
			async showAd() {
				if (getApp().globalData.showAd) {
					let _that = this
					let index = this.cardCur
					// 在页面中定义插屏广告
					let interstitialAd = null
					// 在页面onLoad回调事件中创建插屏广告实例
					if (uni.createInterstitialAd) {
						let adIdArray = getApp().globalData.interstitialAd
						let index = await this.$func.randomIntFromInterval(0, adIdArray.length - 1)
						console.log(adIdArray[index])
						interstitialAd = uni.createInterstitialAd({
							adUnitId: adIdArray[index]
						})
						interstitialAd.onLoad(() => {})
						interstitialAd.onError((err) => {
							_that.$func.showToast(err.errMsg)
							_that.downloadImage(index)
						})
						interstitialAd.onClose(() => {
							_that.downloadImage(index)
						})
					}
					// 在适合的场景显示插屏广告
					if (interstitialAd) {
						interstitialAd.show().catch((err) => {
							_that.$func.showToast(err.errMsg)
							_that.downloadImage(index)
						})
					}
				}
			},
			subscribe() {
				this.$func.templateSubscribe(getApp().globalData.imageDetailUpdate)
			},
			imagePreview() {
				let previewStatus = uni.getStorageSync("preview_status")
				let _that = this
				if (this.device_type != 1 && previewStatus != 1) {
					uni.showModal({
						title: "操作提示",
						content: "电脑壁纸，建议下载到本地预览",
						confirmText: "不在提示",
						cancelText: "知道了",
						success: function (res) {
							if (res.confirm) {
								uni.setStorageSync("preview_status", 1)
							}
							uni.navigateTo({
								url: "/pageA/details/preview?imageUrl=" + _that.swiperList[_that.cardCur].url + _that.swiperList[_that.cardCur].path
							})
						}
					})
				} else {
					uni.navigateTo({
						url: "/pageA/details/preview?imageUrl=" + _that.swiperList[_that.cardCur].url + _that.swiperList[_that.cardCur].path
					})
				}
				//this.$func.imagePreview(this.swiperList[this.cardCur].url + this.swiperList[this.cardCur].path)
			},
      downloadImage(index) {
				uni.showLoading({
					title: '图片制作中',
				})
				imageDownLoad({image_uid: this.swiperList[index].uid}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.$func.downloadImage(res.url)
						return
					}
					this.$func.showToast(res.msg)
				})
			},
      cardSwiper(e) {
        this.cardCur = e.detail.current
      },
      
      // 弹出压屏窗
      showLandscape() {
        this.openLandscape()
      },
      // 打开压屏窗
      openLandscape() {
        this.show1 = true
      },
      // 关闭压屏窗
      closeLandscape() {
        this.show1 = false
      },
			shareImage() {
				imageShare({image_uid: this.image_uid}).then(res => {
					console.log(res)
				})
			},
			onShareAppMessage(e) {
				console.log(e, '分享好友')
				this.shareImage()
				return {
					title: this.imageContent.title,
				}
			},
			onShareTimeline(e) {
				console.log(e, '分享朋友圈')
				this.shareImage()
				return {
					title: this.imageContent.title,
				}
			}
    }
	}
</script>

<style lang="scss" scoped>
  .template-details {
    margin: 0;
    width: 100%;
    height: 100vh;
    color: #fff;
    overflow: hidden;
  }
  /* 胶囊*/
  .tn-custom-nav-bar__back {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    box-sizing: border-box;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 1000rpx;
    border: 1rpx solid rgba(255, 255, 255, 0.5);
    color: #FFFFFF;
    font-size: 18px;
    
    .icon {
      display: block;
      flex: 1;
      margin: auto;
      text-align: center;
    }
    
    &:before {
      content: " ";
      width: 1rpx;
      height: 110%;
      position: absolute;
      top: 22.5%;
      left: 0;
      right: 0;
      margin: auto;
      transform: scale(0.5);
      transform-origin: 0 0;
      pointer-events: none;
      box-sizing: border-box;
      opacity: 0.7;
      background-color: #FFFFFF;
    }
  }  
  

  
  /* 图标容器15 start */
  .icon15 {
    &__item {
      width: 30%;
      
      border-radius: 10rpx;
      padding: 30rpx;
      margin: 20rpx 10rpx;
      transform: scale(1);
      transition: transform 0.3s linear;
      transform-origin: center center;
      
      &--icon {
        width: 100rpx;
        height: 100rpx;
        font-size: 50rpx;
        border-radius: 50%;
        margin-bottom: 18rpx;
        position: relative;
        z-index: 1;
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
  
            
        }
      }
    }
  }
  
  /* 按钮 */
  .button-1 {
    background-color: rgba(0, 0, 0, 0.15);
    position: fixed;
    /* bottom:200rpx;
      right: 20rpx; */
    top: 25%;
    right: 30rpx;
    z-index: 1001;
    border-radius: 100px;
  }
  .button-2 {
    background-color: rgba(0, 0, 0, 0.15);
    position: fixed;
    /* bottom:200rpx;
      right: 20rpx; */
    top: 35%;
    right: 30rpx;
    z-index: 1001;
    border-radius: 100px;
  }
  .button-3 {
    background-color: rgba(0, 0, 0, 0.15);
    position: fixed;
    /* bottom:200rpx;
      right: 20rpx; */
    top: 45%;
    right: 30rpx;
    z-index: 1001;
    border-radius: 100px;
  }  
  .button-4 {
		background-color: rgba(0, 0, 0, 0.15);
		position: fixed;
		/* bottom:200rpx;
		  right: 20rpx; */
		top: 55%;
		right: 30rpx;
		z-index: 1001;
		border-radius: 100px;
	}
    

  
  /* 相册 start*/
  .slideshow {
    top: 0;
    position: absolute;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }
  
  .slideshow-image {
    position: absolute;
    width: 100%;
    height: 100%;
    background: no-repeat 50% 50%;
    background-size: cover;
    -webkit-animation-name: kenburns;
            animation-name: kenburns;
    -webkit-animation-timing-function: linear;
            animation-timing-function: linear;
    -webkit-animation-iteration-count: infinite;
            animation-iteration-count: infinite;
    -webkit-animation-duration: 16s;
            animation-duration: 16s;
    opacity: 1;
    transform: scale(1.2);
  }
  .slideshow-image:nth-child(1) {
    -webkit-animation-name: kenburns-1;
            animation-name: kenburns-1;
    z-index: 3;
  }
  .slideshow-image:nth-child(2) {
    -webkit-animation-name: kenburns-2;
            animation-name: kenburns-2;
    z-index: 2;
  }
  .slideshow-image:nth-child(3) {
    -webkit-animation-name: kenburns-3;
            animation-name: kenburns-3;
    z-index: 1;
  }
  .slideshow-image:nth-child(4) {
    -webkit-animation-name: kenburns-4;
            animation-name: kenburns-4;
    z-index: 0;
  }
  
  @-webkit-keyframes kenburns-1 {
    0% {
      opacity: 1;
      transform: scale(1.2);
    }
    1.5625% {
      opacity: 1;
    }
    23.4375% {
      opacity: 1;
    }
    26.5625% {
      opacity: 0;
      transform: scale(1);
    }
    100% {
      opacity: 0;
      transform: scale(1.2);
    }
    98.4375% {
      opacity: 0;
      transform: scale(1.2117647059);
    }
    100% {
      opacity: 1;
    }
  }
  
  @keyframes kenburns-1 {
    0% {
      opacity: 1;
      transform: scale(1.2);
    }
    1.5625% {
      opacity: 1;
    }
    23.4375% {
      opacity: 1;
    }
    26.5625% {
      opacity: 0;
      transform: scale(1);
    }
    100% {
      opacity: 0;
      transform: scale(1.2);
    }
    98.4375% {
      opacity: 0;
      transform: scale(1.2117647059);
    }
    100% {
      opacity: 1;
    }
  }
  @-webkit-keyframes kenburns-2 {
    23.4375% {
      opacity: 1;
      transform: scale(1.2);
    }
    26.5625% {
      opacity: 1;
    }
    48.4375% {
      opacity: 1;
    }
    51.5625% {
      opacity: 0;
      transform: scale(1);
    }
    100% {
      opacity: 0;
      transform: scale(1.2);
    }
  }
  @keyframes kenburns-2 {
    23.4375% {
      opacity: 1;
      transform: scale(1.2);
    }
    26.5625% {
      opacity: 1;
    }
    48.4375% {
      opacity: 1;
    }
    51.5625% {
      opacity: 0;
      transform: scale(1);
    }
    100% {
      opacity: 0;
      transform: scale(1.2);
    }
  }
  @-webkit-keyframes kenburns-3 {
    48.4375% {
      opacity: 1;
      transform: scale(1.2);
    }
    51.5625% {
      opacity: 1;
    }
    73.4375% {
      opacity: 1;
    }
    76.5625% {
      opacity: 0;
      transform: scale(1);
    }
    100% {
      opacity: 0;
      transform: scale(1.2);
    }
  }
  @keyframes kenburns-3 {
    48.4375% {
      opacity: 1;
      transform: scale(1.2);
    }
    51.5625% {
      opacity: 1;
    }
    73.4375% {
      opacity: 1;
    }
    76.5625% {
      opacity: 0;
      transform: scale(1);
    }
    100% {
      opacity: 0;
      transform: scale(1.2);
    }
  }
  @-webkit-keyframes kenburns-4 {
    73.4375% {
      opacity: 1;
      transform: scale(1.2);
    }
    76.5625% {
      opacity: 1;
    }
    98.4375% {
      opacity: 1;
    }
    100% {
      opacity: 0;
      transform: scale(1);
    }
  }
  @keyframes kenburns-4 {
    73.4375% {
      opacity: 1;
      transform: scale(1.2);
    }
    76.5625% {
      opacity: 1;
    }
    98.4375% {
      opacity: 1;
    }
    100% {
      opacity: 0;
      transform: scale(1);
    }
  }
    /* 相册 end*/
    
  /* 用户头像 start */
  .logo-image {
    width: 100rpx;
    height: 100rpx;
    position: relative;
  }
  
  .logo-pic {
    background-size: cover;
    background-repeat: no-repeat;
    // background-attachment:fixed;
    background-position: top;
    border: 6rpx solid rgba(255,255,255,0.25);
    box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
    border-radius: 50%;
    overflow: hidden;
    // background-color: #FFFFFF;
  }
    
  /* 底部tabbar start*/
  /* 毛玻璃*/
  .dd-glass {
     width: 100%;
     backdrop-filter: blur(20rpx);
    -webkit-backdrop-filter: blur(20rpx);
  }
  
  .footerfixed{
   position: fixed;
   // margin: 20rpx;
   margin: 40rpx 5%;
   width: 90%;
   bottom: calc(env(safe-area-inset-bottom) / 2);;
   z-index: 999;
   background-color: rgba(0, 0, 0, 0.15);
   box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
  }
  
  .tabbar {
    display: flex;
    align-items: center;
    min-height: 110rpx;
    justify-content: space-between;
  	padding: 0;
  	height: calc(110rpx + env(safe-area-inset-bottom) / 2);
  	// padding-bottom: calc(env(safe-area-inset-bottom) / 2);
  }
  
  .tabbar .action {
  	font-size: 22rpx;
  	position: relative;
  	flex: 1;
  	text-align: center;
  	padding: 0;
  	display: block;
  	height: auto;
  	line-height: 1;
  	margin: 0;
  	overflow: initial;
  }
  
  .tabbar .action .bar-icon {
  	width: 100rpx;
  	position: relative;
  	display: block;
  	height: auto;
  	margin: 0 auto 10rpx;
  	text-align: center;
  	font-size: 42rpx;
  }
  
  .tabbar .action .bar-icon image {
  	width: 50rpx;
  	height: 50rpx;
  	display: inline-block;
  }  
  
  
  /* 全屏轮播  start*/
  .card-swiper {
    height: 100vh !important;
  }
    
  .card-swiper swiper-item {
    width: 750rpx !important;
    left: 0rpx;
    box-sizing: border-box;
    overflow: initial;
  }
    
  .card-swiper swiper-item .swiper-item {
    width: 100%;
    display: block;
    height: 100vh;
    border-radius: 0rpx;
    transform: scale(0.9);
    transition: all 0.2s ease-in 0s;
    will-change: transform;
    overflow: hidden;
  }
    
  .card-swiper swiper-item.cur .swiper-item {
    transform: scale(1);
    transition: all 0.2s ease-in 0s;
    will-change: transform;
  }
    
  .image-banner{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .image-banner image{
    width: 100%;
    // height: 100%;
  }
  
  /* 轮播指示点 start*/
  .indication{
    z-index: 9999;
    width: 100%;
    height: 36rpx;
    position: fixed;
    display:flex;
    flex-direction:row;
    align-items:center;
    justify-content:center;
  }
  
  .spot{
    background-color: #FFFFFF;
    opacity: 0.6;
    width: 10rpx;
    height: 10rpx;
    border-radius: 20rpx;
    top: calc(-280rpx - env(safe-area-inset-bottom) / 2);
    top: calc(-280rpx - constant(safe-area-inset-bottom));
    margin: 0 8rpx !important;
    position: relative;
  }
  
  .spot.active{
    opacity: 1;
    width: 30rpx;
    background-color: #FFFFFF;
  }
</style>
